package com.googlecode.jmicroerp.service;

import com.googlecode.jmicroerp.model.Magazin;
import com.googlecode.jmicroerp.model.ProgramLucru;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import net.ftlines.wicket.fullcalendar.Event;
import net.ftlines.wicket.fullcalendar.EventNotFoundException;
import net.ftlines.wicket.fullcalendar.EventProvider;
import org.joda.time.DateTime;
import org.springframework.stereotype.Service;

/**
 *
 * @author alex
 */
@Service(value = "programLucruProvider")
public class ProgramLucruProvider implements EventProvider {

    private Magazin magazin;

    public Magazin getMagazin() {
        return magazin;
    }

    public void setMagazin(Magazin magazin) {
        this.magazin = magazin;
    }

    private Event createEvent(ProgramLucru zi) {
        Event event = new Event();
        event.setId(zi.getId().toString());
        event.setStart(new DateTime(zi.getOraInceput().getTime()));
        event.setEnd(new DateTime(zi.getOraSfarsit().getTime()));
        event.setTitle("Creat de "
                + zi.getCreatedBy().getNumeUtilizator()
                + " modificat de "
                + zi.getLastModifiedBy().getNumeUtilizator());
        return event;
    }

    @Override
    public Collection<Event> getEvents(DateTime start, DateTime stop) {
        List<ProgramLucru> program = new ArrayList<ProgramLucru>();

        ProgramLucru ziL = new ProgramLucru();
        ziL.setZi(new Date());
        ziL.setOraInceput(new Date());
        Date hhStop = new Date();
        hhStop.setTime(hhStop.getTime() + 1000 * 60);
        ziL.setOraSfarsit(hhStop);

        program.add(ziL);

        List<Event> events = new ArrayList<Event>(program.size());

        for (ProgramLucru zi : program) {
            Event event = createEvent(zi);
            events.add(event);
        }

        return events;
    }

    @Override
    public Event getEventForId(String string) throws EventNotFoundException {
        ProgramLucru zi = new ProgramLucru();
        return createEvent(zi);
    }
}
